package me.boot.web.websocket;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.*;
import org.springframework.web.socket.handler.TextWebSocketHandler;

/**
 * @Description:
 * @author: Sylar
 * @date: 2022年11月21日 10:59
 */
@Slf4j
@Component
public class DefaultWebSocketHandler extends TextWebSocketHandler {

    @Override
    protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
        log.info(StrUtil.format("id:{},msg:{}", session.getId(), message.getPayload()));
        session.sendMessage(new TextMessage(StrUtil.format("自动答复:{}", message.getPayload())));
    }
}
